package com.example.petcare.mapper;

import com.example.petcare.pojo.HostDemand;
import com.example.petcare.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OrderMapper {

    // 查询订单列表（条件分页查询）
    List<HostDemand> list(Integer status, Integer orderStatus, Integer providerId);

    // 查询订单
    @Select("select * from host_demand where host_id = #{hostId} and pay_status = 1")
    HostDemand selectById(Integer hostId);

    // 更新订单状态(status)
    @Update("update host_demand set status = #{status} ,provider_id = #{providerId} where host_id = #{hostId}")
    void updateStatus(HostDemand hostDemand);

    // 更新订单状态(orderStatus)
    @Update("update host_demand set order_status = #{orderStatus} where host_id = #{hostId}")
    void updateOrderStatus(HostDemand hostDemand);


    // 更新订单状态(rejectStatus)和(orderStatus)
    @Update("update host_demand set reject_status = #{rejectStatus}, order_status = #{orderStatus} where host_id = #{hostId}")
    void updateRejectStatus(HostDemand hostDemand);

    // 是否有新订单，查询订单状态为0的订单的数量
    @Select("select count(*) from host_demand where  status = 0 and pay_status = 1")
    Integer hasNewOrder();


    // 查询用户信息
    @Select("select * from user where user_id = #{userId}")
    User selectUserById(Integer userId);
}
